#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

void Swap(int arr[], int x, int y)
{
	int temp = arr[x];
	arr[x] = arr[y];
	arr[y] = temp;
}

void SortColor(int arr[], int sz)
{
	int i = 0;
	int left = 0;
	int right = sz - 1;
	while (i <= right)
	{
		if (arr[i] == 0)
		{
			Swap(arr, left, i);
			left++;
			i++;
		}
		else if (arr[i] == 1)
		{
			i++;
		}
		else if(arr[i] == 2)
		{
			Swap(arr, right, i);
			right--;
		}

	}
}

int main()
{
	int arr[] = {2,1,0,2,1,0,2,1,2,1,2,1,2,0};
	int sz = sizeof(arr) / sizeof(arr[0]);
	SortColor(arr, sz);
	for (int i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}




